const Router = require('koa-router');
const router = new Router({
  prefix: 'v1/book/'
});

const { HotBook } = require('../../models/hot-book');
const { Book } = require('../../models/book.js');

router.get('hot_list', async (ctx, next) => {
  const books = await HotBook.getAll();
  ctx.body = books;
});

router.get(':id/detail', (ctx, next) => {
  // const v = await new validator().validate(ctx);
  const book = new Book();
  ctx.body = book.detail(v.get('path.id'));
});

router.get('search', async (ctx, next) => {
  const v = await new searchValidator().validate(ctx);
  const book = Book.searchFromYunShu(v.get('query.q'),v.get('query.start'),v.get('query.count'),);
  ctx.body = book;
});

router.get('favor/count', new Auth().m, async(ctx, next) => {
  const v = await Book.getMyFavorBookCount(ctx.auth.uid);
  ctx.body = {
    count
  };
});

module.exports = router;